#include <algorithm>
#include <iostream>
#include "Deck.h"

using namespace std;

Deck::Deck()
	{
		mbr_LastIndexOfCardOfDeckToDeal =51;
		populate();
	}

void Deck::populate()
	{
		for(int i=0;i<4;++i)
		{
			for(int j=1;j<14;++j)
			{
				cardDeck.push_back(Card(i/*cardType*/, j/*cardNumber*/));//create a card from the enum card types
			}
		}
	}
   
void Deck::shuffle()
{
    random_shuffle (cardDeck.begin(), cardDeck.end());
}

void Deck::dealOneCard(Hand &hand)
{
     //check if the deck is emptied untill now.
    if(mbr_LastIndexOfCardOfDeckToDeal!=0)
    {
        hand.add(&(cardDeck.at(mbr_LastIndexOfCardOfDeckToDeal)));
		--mbr_LastIndexOfCardOfDeckToDeal;                
    }
	else cout<<"Can't deal cards, Deck is Empty";//print out error if there is no card left in the deck
}
   
void Deck::giveCards(GenericPlayer &tmpGenericPlayer)
{
  while(!tmpGenericPlayer.isBusted() && tmpGenericPlayer.isHitting())
  {
	  if(mbr_LastIndexOfCardOfDeckToDeal!=0)
	  {
			tmpGenericPlayer.add(&cardDeck.at(mbr_LastIndexOfCardOfDeckToDeal));
			--mbr_LastIndexOfCardOfDeckToDeal;
	  }
	  else cout<<"Can't give cards, Deck is Empty";//print out error if there is no card left in the deck
  }
}